package cn.wolfcode.web.controller;

import cn.wolfcode.domain.SystemDictionary;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.ISystemDictionaryService;
import cn.wolfcode.util.RequirePermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/systemDictionary")
public class SystemDictionaryController {
    @Autowired
    private ISystemDictionaryService systemDictionaryService;

    //字典目录页面的增删改查

    //查
    @RequirePermission(name = "字典目录页面",expression = "systemDictionary:list")
    @RequestMapping("/list")
    public String query(QueryObject qo, Model model){
        PageInfo<SystemDictionary> pageInfo = systemDictionaryService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        //返回的JSP视图
        return "systemDictionary/list";
    }

    //删
    @RequirePermission(name = "字典目录删除",expression = "systemDictionary:delete")
    @RequestMapping("/delete")
    public String delete(Long id){
        systemDictionaryService.delete(id);
        //重定向会原来的list页面
        return "redirect:/systemDictionary/list";
    }

    //增改
    @RequirePermission(name = "字典目录新增/编辑",expression = "systemDictionary:saveOrUpdate")
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(SystemDictionary systemDictionary){
        systemDictionaryService.saveOrUpdate(systemDictionary);
        return "redirect:/systemDictionary/list";
    }
}
